package com.loriot.common.min_cost_climbing_stairs_746;

public class Main {
    class Solution {
        public int minCostClimbingStairs(int[] cost) {
            // dp[i] = Math.min(dp[i-1]+cost[i-1],dp[i-2]+cost[i-2]);
            int[] dp = new int[cost.length+1];
            dp[0] = 0;
            dp[1] = 0;
            for(int i=2;i<cost.length+1;i++){
                dp[i] = Math.min(dp[i-1]+cost[i-1],dp[i-2]+cost[i-2]);
            }
            return dp[cost.length];
        }
    }

    class Solution2 {
        public int minCostClimbingStairs(int[] cost) {
            // 跳到0需要
            int a = 0;
            // 跳到1需要
            int b = 0;
            // 跳到cost.length需要
            for(int i=2;i<cost.length+1;i++){
                int k = Math.min(b+cost[i-1],a+cost[i-2]);
                a = b;
                b = k;
            }
            return b;
        }
    }

}
